/* cl.ext.colorbox 0.1*/
(
    function (factory) {
        if (typeof define === 'function' && define.amd) {
            define(['jquery',"ColorBox"], factory);
        } else if (typeof module === 'object' && module.exports) {
            var reqColorBox = require('ColorBox');
            module.exports = function( root, jQuery ) {
                if ( jQuery === undefined ) {
                    if ( typeof window !== 'undefined' ) {
                        jQuery = require('jquery');
                    }
                    else {
                        jQuery = require('jquery')(root);
                    }
                }
                factory(jQuery);
            };
        } else {
            factory(jQuery);
        }
    }(
    function ($){
        var defaultExtInfo={};
        var defaults={trapFocus:false, current:'{current} / {total}',xhrError:"图片链接不存在",imgError:"图片链接不存在", infoExt:defaultExtInfo};
        var $modalCommon={
            getDefaults :function () {
                return defaults
            },
            getOptions : function (elementData,options) {
                options=$.ExtCommon.isCheckEmpty(options)?{}:options;
                var optionBase =$.ExtCommon.initMergeJson(elementData,options);
                optionBase =$.ExtCommon.initMergeJson(this.getDefaults(),optionBase);
                return optionBase
            }
        };
        var ColorBoxExtModal = function(element, options) {
            var self=this;
            self.element = $(element);
            self.optionBase=$modalCommon.getOptions(self.element.data(),options);
            self.element.colorbox(self.optionBase);
        };
        ColorBoxExtModal.prototype = {
        };
        $.fn.ExtColorBox = function(options) {
            var dataFun;
            this.each(function() {
                var el = $(this);
                var tempData=el.data('ExtColorBox');
                if (tempData) {
                    if (typeof  options === "string") {
                        if (tempData[options]) {
                            dataFun =tempData[options]()
                        } else {
                            dataFun = tempData
                        }
                    } else {
                        dataFun = tempData
                    }
                } else {
                    dataFun = new ColorBoxExtModal(el, options);
                    el.data('ExtColorBox', dataFun);
                }
            });
            return dataFun;
        };
        return ColorBoxExtModal;
    })
);
